#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012 Audiokinetic Inc. / All Rights Reserved
//
//////////////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Reflection;
using UnityEngine;

public class AkBasePathGetter
{
	public static string GetPlatformName()
	{
		string platformSubDir = "Undefined platform sub-folder";

#if UNITY_STANDALONE_LINUX
		platformSubDir = "Linux";
#elif UNITY_XBOXONE
		platformSubDir = "XBoxOne";
#elif UNITY_IOS || UNITY_TVOS
		platformSubDir = "iOS";
#elif UNITY_ANDROID
		platformSubDir = "Android";
#elif UNITY_PS4
		platformSubDir = "PS4";
#elif UNITY_WP_8_1
		platformSubDir = "WindowsPhone";
#elif UNITY_SWITCH
		platformSubDir = "Switch";
#elif UNITY_PSP2
#if AK_ARCH_VITA_SW || !AK_ARCH_VITA_HW
		platformSubDir = "VitaSW";
#else
		platformSubDir = "VitaHW";
#endif
#elif (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_WSA)
        platformSubDir = "Windows";
#elif (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
		platformSubDir = "Mac";
#endif
        return platformSubDir;
	}

	/// Returns the full base path
	public static string GetPlatformBasePath()
	{
        // Get full path of base path
#if UNITY_EDITOR
	    AudioSetting setting = AudioSetting.LoadSettings();
        string fullBasePath = "";
        if (setting.LoadBankFromExportPath)
            fullBasePath = Path.Combine(setting.FullWwiseGeneratedSoundBanksPath, GetPlatformName());
        else
        {
            fullBasePath = Path.Combine(Application.streamingAssetsPath, setting.EditorSoundbankPath);
            fullBasePath = Path.Combine(fullBasePath, GetPlatformName());
        }
#else
#if UNITY_ANDROID
 		string fullBasePath = GetPlatformSoundbankPath();
#else
        string fullBasePath = Path.Combine(Application.streamingAssetsPath, GetPlatformSoundbankPath());
#endif
#endif
#if UNITY_SWITCH
		fullBasePath = fullBasePath.Substring(1);
#endif
        FixSlashes(ref fullBasePath);
        return fullBasePath;
	}

	private static string GetPlatformSoundbankPath()
	{
		string platformBasePath = Path.Combine(AkInitializer.c_DefaultBasePath, GetPlatformName());
		return platformBasePath;
	}

	public static bool CheckSoundbankBasePath(string basepath)
	{
		bool InitBnkFound = true;
#if UNITY_EDITOR || !UNITY_ANDROID // Can't use File.Exists on Android, assume banks are there
		string InitBankPath = Path.Combine(basepath, "Init.bnk");
		if (!File.Exists(InitBankPath))
		{
			InitBnkFound = false;
		}
#endif

		if (basepath == string.Empty || InitBnkFound == false)
		{
			AkSoundEngine.Log("WwiseUnity: Looking for SoundBanks in " + basepath);

#if UNITY_EDITOR
			AkSoundEngine.LogError("WwiseUnity: Could not locate the SoundBanks. Did you make sure to generate them?");
#else
			AkSoundEngine.LogError("WwiseUnity: Could not locate the SoundBanks. Did you make sure to copy them to the StreamingAssets folder?");
#endif
		}
		return InitBnkFound;
	}


    	private static void FixSlashes(ref string path, char separatorChar, char badChar, bool addTrailingSlash)
	{
		if (string.IsNullOrEmpty(path))
			return;

		path = path.Trim().Replace(badChar, separatorChar).TrimStart('\\');

		// Append a trailing slash to play nicely with Wwise
		if (addTrailingSlash && !path.EndsWith(separatorChar.ToString()))
			path += separatorChar;
	}

	public static void FixSlashes(ref string path)
	{
#if UNITY_WSA
		char separatorChar = '\\';
#else
		char separatorChar = Path.DirectorySeparatorChar;
#endif // UNITY_WSA
		char badChar = separatorChar == '\\' ? '/' : '\\';
		FixSlashes(ref path, separatorChar, badChar, true);
	}

}

#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.